package com.crab.framework.mybatis;

import com.crab.business.example.dao.ExampleBeanMapper;
import com.crab.business.example.model.ExampleBean;
import com.github.pagehelper.PageHelper;
import org.apache.ibatis.session.RowBounds;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import tk.mybatis.mapper.common.Mapper;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * Created by liusk on 2016/7/28.
 */
public class BaseService<T> {

    @Autowired
    private SqlSessionTemplate template;

    @Autowired
    protected Mapper<T> mapper;

    public int insert(T entity) {
        return mapper.insert(entity);
    }

    public int insertSelective(T entity) {
        return mapper.insertSelective(entity);
    }

    public int delete(T entity) {
        return mapper.delete(entity);
    }

    public int deleteByExample(T entity) {
        return mapper.deleteByExample(entity);
    }

    public int deleteByPrimaryKey(T entity) {
        return mapper.deleteByPrimaryKey(entity);
    }

    public int updateByPrimaryKey(T entity) {
        return mapper.updateByPrimaryKey(entity);
    }

    public int updateByExample(T entity, Example example) {
        return mapper.updateByExample(entity, example);
    }

    public int updateByExampleSelective(T entity, Example example) {
        return mapper.updateByExampleSelective(entity, example);
    }

    public int updateByPrimaryKeySelective(T entity) {
        return mapper.updateByPrimaryKeySelective(entity);
    }

    public List<T> select(T entity) {
        return mapper.select(entity);
    }

    public List<T> selectAll() {
        return mapper.selectAll();
    }

    public List<T> selectByExample(Example example) {
        return mapper.selectByExample(example);
    }

    public List<T> selectByExampleAndRowBounds(Example example, RowBounds rowBounds) {
        return mapper.selectByExampleAndRowBounds(example, rowBounds);
    }

    public List<T> selectByRowBounds(T record, RowBounds rowBounds) {
        return mapper.selectByRowBounds(record, rowBounds);
    }

    public T selectOne(T record) {
        return mapper.selectOne(record);
    }

    public T selectByPrimaryKey(T record) {
        return mapper.selectByPrimaryKey(record);
    }

    public int selectCount(T record) {
        return mapper.selectCount(record);
    }

    public int selectCountByExample(T record) {
        return mapper.selectCountByExample(record);
    }

    public List<T> selectByPage(int pageNum, int pageSize, Example example) {
        PageHelper.startPage(pageNum, pageSize);
        return mapper.selectByExample(example);
    }
}
